pkgname=(madwifi madwifi-utils)
pkgver=4118
pkgrel=1
_kernver=`uname -r`
arch=(i686 x86_64)
license=('GPL')
url="http://www.madwifi-project.org/"
makedepends=('sharutils')

_svntrunk=http://svn.madwifi-project.org/madwifi/trunk
_svnmod=madwifi

build() {
	cd $startdir
	if [ -d $_svnmod/.svn ]; then
		(cd $_svnmod && svn up) || return 1
	else
		svn co $_svntrunk -r $pkgver $_svnmod || return 1
	fi

	[ -d $srcdir/$_svnmod ] && rm -rf $srcdir/$_svnmod
	cp -a $startdir/$_svnmod $srcdir/$_svnmod

	msg "SVN checkout done or server timeout"
	msg "Starting make..."

	[ "${CARCH}" == "i686" ] && export ARCH=i386
	cd $srcdir/$_svnmod
	sed -i -e 's/-Werror//g' Makefile.inc
	make KERNELPATH=/lib/modules/$_kernver/build KERNELRELEASE=$_kernver modules|| return 1
	make tools || return 1
}

package_madwifi(){
	pkgdesc="Madwifi drivers for Atheros wireless chipsets. For stock arch 2.6 kernel"
	provides=('madwifi')
	conflicts=()
	depends=(kernel26=${_kernver%%-*})
	install=madwifi-ng.install

	cd $srcdir/$_svnmod
	make KERNELPATH=/lib/modules/$_kernver/build KERNELRELEASE=$_kernver modules \
	DESTDIR=$pkgdir KERNELRELEASE=$_kernver install-modules
	sed -i -e "s/KERNEL_VERSION='.*'/KERNEL_VERSION='${_kernver}'/" $startdir/*.install

	# install to wireless kernel directory
	mkdir -p $pkgdir/lib/modules/$_kernver/kernel/drivers/net/wireless/madwifi
	mv $pkgdir/lib/modules/$_kernver/net/* $pkgdir/lib/modules/$_kernver/kernel/drivers/net/wireless/madwifi
	rm -r $pkgdir/lib/modules/$_kernver/net/
}

package_madwifi-utils(){
	pkgdesc="Userspace tools of madwifi drivers for Atheros wireless chipsets."
	depends="madwifi"
	provides=("madwifi-ng-utils" 'madwifi-utils')
	conflicts=("madwifi-ng-utils" 'madwifi-utils')

	cd $srcdir/$_svnmod
	make DESTDIR=$pkgdir BINDIR=/usr/bin MANDIR=/usr/share/man install-tools
}
